﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Resxus.Model;

namespace Resxus.DataAccess
{
    public class ResFilesRepository : ICollection<ResourceFile>
    {
        public event Action<ResourceFile> AddFile;
        public event Action ClearFiles;
        public event Action<ResourceFile> RemoveFile;

        private List<ResourceFile> _Files = new List<ResourceFile>();

        public ResFilesRepository()
        {

        }
        
        public ICollection<ResourceFile> Items
        {
            get
            {
                return this;
            }
        }

        #region ICollection<ResourceFile> 멤버

        void ICollection<ResourceFile>.Add(ResourceFile item)
        {            
            this._Files.Add(item);

            //이벤트 
            if (this.AddFile != null)
            {
                this.AddFile(item);
            }
        }

        void ICollection<ResourceFile>.Clear()
        {
            this._Files.Clear();

            if (this.ClearFiles != null)
            {
                this.ClearFiles();
            }
        }

        bool ICollection<ResourceFile>.Contains(ResourceFile item)
        {
            return this._Files.Exists(param => { return param.Equals(item); });
        }

        void ICollection<ResourceFile>.CopyTo(ResourceFile[] array, int arrayIndex)
        {
            this._Files.CopyTo(array, arrayIndex);
        }

        int ICollection<ResourceFile>.Count
        {
            get { return _Files.Count; }
        }

        bool ICollection<ResourceFile>.IsReadOnly
        {
            get { return false; }
        }

        bool ICollection<ResourceFile>.Remove(ResourceFile item)
        {
            bool result = _Files.Remove(item);

            //이벤트 
            if (this.RemoveFile != null)
            {
                this.RemoveFile(item);
            }

            return result;
        }

        #endregion

        #region IEnumerable<ResourceFile> 멤버

        IEnumerator<ResourceFile> IEnumerable<ResourceFile>.GetEnumerator()
        {
            return this._Files.GetEnumerator();
        }

        #endregion

        #region IEnumerable 멤버

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return this._Files.GetEnumerator();
        }

        #endregion
    }
}
